package com.liuhongwei.test.entity.query;

import java.io.Serializable;
import java.util.Collection;

/**
 * @describe 自定义页转换器
 */
public class Page<T> implements Serializable {
    //当前页
    private int currentPage = 1;
    //每页显示条数
    private int pageSize = 0;
    //总条数
    private int totalSize = 0;
    //数据列表
    private Collection<T> list;
    //总页数
//    private int totalPage=1;
    public Page() {
    }

    public Page(int currentPage, int pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

    public Page(int currentPage, int pageSize, int totalSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
    }

    public Page(int currentPage, int pageSize, int totalSize, Collection<T> list) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.list = list;
    }

    public int getTotalPage() {
        if (this.pageSize <= 0) {
            return 1;
        } else {
            int totalPage = this.totalSize / this.pageSize + (this.totalSize % this.pageSize == 0 ? 0 : 1);
            totalPage = this.totalSize == 0 ? 1 : totalPage;
            return totalPage;
        }
    }

    public int getCurrentPage() {
        if (this.currentPage > this.getTotalPage()) {
            return this.getTotalPage();
        } else {
            return this.currentPage < 1 ? 1 : this.currentPage;
        }
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalSize() {
        return this.totalSize;
    }

    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
    }

    public Collection<T> getList() {
        return list;
    }

    public void setList(Collection<T> list) {
        this.list = list;
    }

}
